package com.zy.demo028082.controller;

import com.zy.demo028082.pojo.po.DepartPo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/depart")
public class DepartController {

    private final RestTemplate restTemplate;
    private final String URL = "http://127.0.0.1:8081/depart";

    @PostMapping("/")
    public boolean save(@RequestBody DepartPo po) {
        return restTemplate.postForObject(URL + "/", po, Boolean.class);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        restTemplate.delete(URL + "/" + id);
    }

    @PutMapping("/")
    public void modify(@RequestBody DepartPo po) {
        restTemplate.put(URL + "/", po);
    }

    @GetMapping("/{id}")
    public DepartPo getById(@PathVariable Long id) {
        return restTemplate.getForObject(URL + "/" + id, DepartPo.class);
    }

    @GetMapping("/list")
    public List<DepartPo> getAll() {
        return restTemplate.getForObject(URL + "/list", List.class);
    }
}
